<?php
include('adodb/adodb.inc.php');
include('config.php');
$db = ADONewConnection($_config['dbdriver']);
$db->Connect($_config['server'],$_config['username'],$_config['password'],$_config['database']);
$db->Execute('SET character_set_results=utf8');
$db->Execute('SET collation_connection=utf8_unicode_ci');
$db->Execute('SET NAMES utf8');

$result = $db->GetArray("select customers.key,customers.post_name,customers.post_id,feedlists.id,feeds.credit,feedlists.forum_id,customers.name,feeds.feed_table,feedlists.last,customers.url from feedlists 
left join customers on customer_id = customers.id 
left join feeds on feed_id = feeds.id 
order by id asc");

foreach($result as $key=>$value)
{
	$data = $db->GetArray("select * from ".$value['feed_table']." where id > ".$value['last']);
	foreach($data as $rs)
	{
		$time = time();
		$post['key'] = $value['key'];
		$post['authorid'] = $value['post_id'];
		$post['fid'] = $value['forum_id'];
		$post['ifcheck'] = 1; 
		$post['postdate'] = $time;
		$post['lastpost'] = $time;
		$post['author'] = $value['post_name'];
		$post['lastposter'] = $value['post_name'];
		$post['subject'] = $rs['title'];
		$post['content'] = $rs['detail'].$value['credit']."<p>Post by <a rel='nofollow' href='http://www.monofolio.com'>Monofolio.com</a></p>";
		$post['ifconvert'] = 2;
		if($rs['slug'])post($value['url'],$post);
		$id = $rs['id'];
	}
	$db->Execute('update feedlists set last = '.$id.' where id = '.$value['id']);
}

function post($url,$data)
{
	$ch=curl_init();
	curl_setopt($ch,CURLOPT_URL,$url);
	curl_setopt($ch, CURLOPT_POST, 1);
	curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($data));
	curl_exec($ch);
	curl_close($ch);
}
?>
